package medium.合并区间;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 2580. 统计将重叠区间合并成组的方案数
 * 创建时间：2024-03-27 09:48
 */
public class 统计将重叠区间合并成组的方案数_2580 {
    public static void main(String[] args) {
        Solution s = new Solution();
        int[][] nums=new int[][]{{1,3},{1,2},{5,1},{4,5},{3,3}};
        s.countWays(nums);
    }

    static class Solution {
        public int countWays(int[][] ranges) {
            // 按照第一维排序
            Arrays.sort(ranges, Comparator.comparingInt(a -> a[0]));
            int rsl = 1;
            int max = -1; // 合并区间最右值
            for (int[] range : ranges) {
                // 当前值大于最右区间
                if(range[0] > max) {
                    rsl = rsl * 2 % 1_000_000_007;
                }
                max = Math.max(range[1], max);
            }
            return rsl;
        }
    }
}


